<?php
/**
 * #Celebrate Shieh
 *             ,%%%%%%%%,
 *           ,%%/\%%%%/\%%
 *          ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 *  `%%     `%%%%(__Y__)%%'
 *  //       ;%%%%`\-/%%%'
 * ((       /  `%%%%%%%'
 *  \\    .'          |
 *   \\  /       \  | |
 *    \\/         ) | |
 *     \         /_ | |__
 *     (___________))))))) 攻城湿
 *
 *        _       _
 * __   _(_)_   _(_) __ _ _ __
 * \ \ / / \ \ / / |/ _` |'_ \
 *  \ V /| |\ V /| | (_| | | | |
 *   \_/ |_| \_/ |_|\__,_|_| |_|
 */

namespace App\Services;

use App\Models\System\Format;
use Carbon\Carbon;
use Illuminate\Http\Request;

class FormatService
{
    use Service;

    /**
     * 文件格式首页
     *
     * @return mixed
     */
    public function FormatIndexService()
    {
        $select = [
            'picture', 'picture_size', 'picture_cate', 'file', 'file_size', 'file_cate', 'text', 'text_size',
            'text_cate', 'id',
        ];
        $format = Format::FindModel($select);
        return view('system.format.index', compact('format'));
    }

    /**
     * 文件格式修改
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function FormatUpdateService( $request )
    {
        $adminValidator = $this->getAdminValidator();
        $error          = $this->getErrorCode();
        switch ( $request->input('status') ) {
            case 1:
                $validator = $adminValidator->FormatUpdatePictureValidator($request);
                if ( $validator->first() ) return back()->with('error', $validator->first());
                $data[ 'picture' ]      = $request->input('picture');
                $data[ 'picture_cate' ] = $request->input('picture_cate', 0);
                $data[ 'picture_size' ] = $request->input('picture_size', 0);
                $data[ 'updated_at' ]   = Carbon::now();//获取时间
                Format::UpdateModel($request->input('id'), $data);
                break;
            case 2:
                $validator = $adminValidator->FormatUpdateFileValidator($request);
                if ( $validator->first() ) return back()->with('error', $validator->first());
                $data[ 'file' ]       = trimAll($request->input('file'));
                $data[ 'file_cate' ]  = $request->input('file_cate', 0);
                $data[ 'file_size' ]  = $request->input('file_size', 0);
                $data[ 'updated_at' ] = Carbon::now();
                Format::UpdateModel($request->input('id'), $data);
                break;
            case 3:
                $validator = $adminValidator->FormatUpdateTextValidator($request);
                if ( $validator->first() ) return back()->with('error', $validator->first());
                $data[ 'text' ]       = $request->input('text');
                $data[ 'text_cate' ]  = $request->input('text_cate', 0);
                $data[ 'text_size' ]  = $request->input('text_size', 0);
                $data[ 'updated_at' ] = Carbon::now();
                Format::UpdateModel($request->input('id'), $data);
                break;
            default:
                return back()->with('error', $error::message(1001));
                break;
        }
        return back()->with('success', $error::message(203));
    }

}
